package com.leetcode.LC;

import java.util.LinkedList;
import java.util.Queue;

public class LC239 {
    public int[] maxSlidingWindow(int[] nums, int k) {
        int[] ints = new int[nums.length - k + 1];
        int max = nums[0];
        int index = 0;
        Queue<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < k; i++) {
            queue.add(nums[i]);
            max = Math.max(max, nums[i]);
        }
        ints[index] = max;

        for (int i = k; i < nums.length; i++) {
            queue.add(nums[i]);
            queue.poll();
            max=Integer.MIN_VALUE;
            for (Integer integer : queue) {
                System.out.print(integer+".");
                max = Math.max(max, integer);
            }
            index++;
            ints[index] = max;
            System.out.println((index+1)+":"+max);
        }
        return ints;
    }

    public static void main(String[] args) {
        for (int i : new LC239().maxSlidingWindow(new int[]{1, 3, -1, -3, 5, 3, 6, 7}, 3)) {
            System.out.print(i+",");
        }
    }
}
